package com.honghu.cloud.code;

import java.util.HashMap;
import java.util.Map;

/**
 * 公共服务响应状态码
 * @author shaozhen
 *
 */
public enum ResponseCode {
	//操作成功

	RETURN_CODE_SUCCESS("200","操作成功"),
	UNLOGIN_ERROR("421","未登录异常"),
	NO_PERMISSION("403","无权访问该系统"),
	SYSTEM_ERROR("500","系统内部异常"),
	TIME_OUT("504","上游服务端网关超时"),	
	ILLEGAL_TOKEN("507", "非法token"),
	TOKEN_EXPIRE("508", "token已过期，请重新登录"),
	
	OK("S000A000", null),
	SUCCESS("10000","请求成功、结果处理成功"),		
	FAILURE("10001","请求失败、结果处理失败"),
	PARAM_FORMAT_ERROR("10002","请求失败、参数格式错误"),
	PARAM_ERROR("10003","参数错误"),
	REQ_CANNOT_EMPTY("10004","必要的请求参数不能为空"),
	USER_DOES_NOT_EXIST("10005","用户不存在"),
	QUERY_SUCCESS("10006","数据查询成功"),
	QUERY_NO_DATA("10007","无数据或者结果"),
	
	NOT_AUTHORIZED("11001", "鉴权错误"),
	REQUEST_FORBIDDEN("11002","禁止访问"),
	PARAMETER_ERROR("11003", "参数不合法"),
	USER_NOT_EXISTS_ERROR("11004", "用户不存在"),
	USER_EXISTS_ERROR("11005", "用户已存在"),
	SERVICE_ERROR("11006", "服务异常"),
	
	//cart错误码 自91000起
	CART_NOT_EXISTS_ERROR("91000", "购物车项不存在"),
	BRADNISNULL_CODE("50001", "品牌不存在"),
	GOODSCLASS_CODE_NULL("20001","数据不存在"),
	
	STORE_USER_IS_NULL("30001","店铺的店主不存在"),
	USER_NO_STORES("30002","未开店"),
	AGENT_GOODS_ADD_REPEAT_ISNULL("30003","代理商品添加重复"),
	;
	
	
	
	private String code; //状态码  
    private String message; //返回消息
    private static String version = "v1.0"; //版本号
    
    // 构造方法  
    private ResponseCode(String code,String message) {  
        this.code = code;  
        this.message = message;  
    }  
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}

	public static ResponseVO buildEnumResponseVO(ResponseCode vitalResponseCode, Object data) {
		return new ResponseVO(vitalResponseCode.getCode(),vitalResponseCode.getMessage(),data);
	}
	
	public static Map<String, Object> buildReturnMap(ResponseCode vitalResponseCode, Object data) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("code", vitalResponseCode.getCode());
		map.put("message", vitalResponseCode.getMessage());
		map.put("data", data);
		return map;
	}
	
	/**
	 * 自定义状态码返回结果Map
	 * @param code  状态码
	 * @param message 消息提示
	 * @param data 数据
	 * @return
	 */
	public static Map<String, Object> buildCodeMap(String code, String message, Object data) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("code", code);
		map.put("version", version);
		map.put("message", message);
		map.put("data", data);
		return map;
	}
	
	/**
	 * 根据枚举返回
	 * @param enumCode  枚举类
	 * @param data 数据
	 * @return
	 */
	public static Map<String, Object> buildEnumMap(ResponseCode enumCode, Object data) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("code", enumCode.code);
		map.put("version", version);
		map.put("message", enumCode.message);
		map.put("data", data);
		return map;
	}
	
	public static Map<String, Object> buildFailMap(String message, Object data) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("code", FAILURE.code);
		map.put("version", version);
		map.put("message", message);
		map.put("data", data);
		return map;
	}
	
	public static Map<String, Object> buildSuccessMap(Object data) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("code", SUCCESS.code);
		map.put("version", version);
		map.put("message", SUCCESS.message);
		map.put("data", data);
		return map;
	}
}
